// PCMod Install Disk \\

SWEP.PrintName = "PC Install Disk"
SWEP.Author = "[GU]|ZLC|thomasfn"
SWEP.Contact = "Don't."
SWEP.Category = "PCMod"
SWEP.Purpose = "To install programs onto a PC."
SWEP.Instructions = "Left click a PC to install program onto. Right click to change program."

SWEP.IsInstallDisk = true

if CLIENT then
	SWEP.Slot 				= 5
	SWEP.DrawAmmo 			= false
	SWEP.DrawCrosshair 		= true
	SWEP.ViewModelFOV		= 70
	SWEP.ViewModelFlip		= false
end

if SERVER then
	AddCSLuaFile("shared.lua")
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo		= true
	SWEP.AutoSwitchFrom		= false
end

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.HoldType = "pistol"

SWEP.Primary.Ammo = "none"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false

SWEP.Secondary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false

SWEP.ProgramList = {
	"GChat",
	"RouterMaster",
	"WireClient",
	"Pong",
	"PrinterSoft",
	"FileViewer",
	"MusicX",
	"WebBrowse",
	"AlarmZ"
}

SWEP.ProgramID = 1

SWEP.ViewModel = "models/weapons/v_c4.mdl"
SWEP.WorldModel = "models/weapons/w_c4.mdl"

if (SERVER) then

	SWEP.Program = "GChat"
	
	function SWEP:Initialize()
		self:SetWeaponHoldType(self.HoldType)
		self:SelectProgram( 1 )
	end
	
	function SWEP:SelectProgram( ID )
		self.Program = self.ProgramList[ ID ]
		self.ProgramID = ID
		self:SetNWString( "prog", self.Program )
	end
	
	function SWEP:PrimaryAttack()
		// Check if we are looking at an entity
		local trace = {}
		trace.start = self.Owner:EyePos()
		trace.endpos = trace.start + self.Owner:GetAimVector() * 200
		trace.filter = self.Owner
		local tr = util.TraceLine(trace)
		
		// Check if that entity is ours - if so, install the prog
		if (tr.Entity) then
			if (tr.Entity.IsPC) then
				ent = tr.Entity
				entid = ent:EntIndex()
				
				if (ent.Data[entid].Status != 3) then
					self.Owner:PrintMessage( HUD_PRINTTALK, "That PC is not on!" )
					return false
				end
				
				ent:InstallProgram( self.Program )
				
				self.Owner:PrintMessage( HUD_PRINTTALK, "Program installed!" )
			end
		end
		
		// We were successful
		return true
	end
	
	function SWEP:SecondaryAttack()
		// Change to next program
		local newid = self.ProgramID + 1
		if (newid > #self.ProgramList) then newid = 1 end
		self:SelectProgram( newid )
	end

end

if (CLIENT) then

	function SWEP:DrawHUD()
		local x = ScrW() * 0.85
		local labelcnt = #self.ProgramList
		local sizeperlbl = 20
		local h = labelcnt * sizeperlbl
		local w = ScrW()-x
		local y = ScrH()-h
		surface.SetDrawColor( 50, 50, 50, 200 )
		surface.DrawRect( x, y, w, h )
		for k, v in pairs( self.ProgramList ) do
			if (v == self:GetNWString( "prog" )) then
				surface.SetDrawColor( 50, 50, 150, 200 )
				surface.DrawRect( x, y+((k-1)*sizeperlbl), w, sizeperlbl )
			end
			draw.SimpleText( v, "PCText", (x+(w/2)), (y+((k-0.5)*sizeperlbl)), Color(255, 255, 255, 255), 1, 1 )
		end
		surface.SetDrawColor( 50, 50, 50, 255 )
		surface.DrawLine( x, y, x, y+h )
		surface.DrawLine( x, y, x+w, y )
	end

end